{% extends 'layouts/bbs.html' %}
{% load navtag %}
{% block nav %}
  {% nav "cooperate" %}
  {{ block.super }}
{% endblock %}

{% block content %}
  {% if message %}
    <div class="alert alert-danger" role="alert">
      {{ message | safe }}
    </div>
  {% endif %}
  <ul class="nav nav-pills nav-justified step step-arrow">
    <li><a style="cursor:default;">填写投票信息</a></li>
    <li class="active"><a>填写投票选项</a></li>
  </ul>
  <div class="clear"></div>
  {{ vote.info }}
  {% for vp in vote_options %}
    {% include 'vote/_vote_option.html' %}
  {% endfor %}
  <div class="add_box"></div>
  <form action="/vote/add_vote_option" method="post">
    <input type="hidden" name="user" value="{{ request.user.pk }}">
    <input type="hidden" name="vote" value="{{ vote.id }}">
    <div class="form-group">
      <textarea class="form-control" rows="10" placeholder="在此填写您的投票描述" name="content"></textarea>
    </div>
    <a class="btn btn-info to_show" style="float: right;">发起投票</a>
    <a class="btn btn-info add" style="float: right; margin-right: 20px;">添加投票选项</a>
    <a class="btn btn-info" style="float: right; margin-right: 20px;">预览</a>
  </form>
  <script>
  $('.add').click(function () {
    $.ajax({
      'url' : '/vote/add_vote_option',
      'type' : 'post',
      'data' : $(this).closest('form').serialize(),
      success : function (data) {
        if(data.msg == 'true'){
          alert_msg(data.errors);
        } else {
          $('.add_box').append(data);
        }
      }
    })
  });

  $('.to_show').click(function () {
    window.location.href = '/vote/show/' + '{{ vote.id }}'
  });
  </script>
{% endblock %}